import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import {
  PlayerModelData,
  PlayerModelDataDocument,
} from './entities/player-model-datum.entity';
import { Model } from 'mongoose';

@Injectable()
export class PlayerModelDataService {
  constructor(
    @InjectModel(PlayerModelData.name)
    private schemaModel: Model<PlayerModelDataDocument>,
  ) {}
  async findAll() {
    const data = await this.schemaModel.find().exec();
    return data.map((item) => ({
      ...item.toObject(),
      roles: new Map(item.roles),
    }));
  }

  async findOne(id: number) {
    const data = await this.schemaModel.findById(id).exec();
    data.roles = new Map(data.roles);
    return data;
  }

  remove(id: number) {
    return this.schemaModel.findByIdAndDelete(id);
  }
}
